package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.qf.dao.StudentMapper;
import com.qf.pojo.Student;
import com.qf.service.StudentService;
import com.qf.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 54110 on 2021/4/16.
 */
@Service
public class StudentServiceImpl  implements StudentService {

    @Autowired
    StudentMapper studentMapper;

    @Override
    public List<Student> findAll(Integer page,Integer size) {
        PageHelper.startPage(page,size);
       List<Student> studentLists= studentMapper.findAll();
        return  studentLists;
    }

    @Override
    public BaseResult delById(Integer id) {

       int i = studentMapper.delById(id);
        //声明返回值
        BaseResult baseResult = new BaseResult();
        if (i>0){
            baseResult.setCode(0);
            baseResult.setMessage("删除成功");
            return baseResult;
        }else{
            baseResult.setCode(1);
            baseResult.setMessage("删除失败");
            return baseResult;
        }
    }

    @Override
    public BaseResult updateById(Student student) {
      int i =  studentMapper.updateById(student);
        BaseResult baseResult = new BaseResult();
        if (i>0){
            baseResult.setCode(0);
            baseResult.setMessage("修改成功");
            return baseResult;
        }else{
            baseResult.setCode(1);
            baseResult.setMessage("修改失败");
            return baseResult;
        }
    }
}
